<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //promise的catch方法用于指定失败时执行的操作
        const p = new Promise((resolve, reject)=>{
            setTimeout(()=>{
                reject("出错了")
            }, 1000)
        })

        //旧写法
        p.then(value=>console.log('成功:' + value), reason=>console.warn('失败:' + reason))
    
        //新写法，then可以不写
        p.then(value=>console.log('成功2:' + value)) 
        .catch(reason=>console.warn('失败2:' + reason))
    
    </script>
</body>
</html>